home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / zbpc_460.zip / UTILITY.EXE / KEYTRAP.BAS < prev    next >
BASIC Source File  |  1991-04-08  |  4KB  |  111 lines

  1. DIM Key$(14),Keyname$(14),FunctionKey$(10),FKey$(10),OtherKey$(10),OKey$(10)
  2. DIM ShiftFKey$(10),AltFKey$(10),CtrlFKey$(10),Bit$(14)
  3. DEF SEG=0
  4.  
  5. COLOR ,31
  6. CLS
  7. PRINT @(0,17)"BIN$ &H417 = "
  8. PRINT@(40,17)"BIN$ &H418 = "
  9. PRINT@ (10,24)"Enter key combination to display or Press Space Bar to End"
  10. PRINT@ (10,19)"If length of INKEY$ = 2 and RIGHT$ (INKEY$) is"
  11.  
  12. FOR X = 1 TO 14 : READ Keyname$(X),Bit$(X) : NEXT
  13. FOR X = 1 TO 10
  14.   READ FunctionKey$(X),FKey$(X),ShiftFKey$(X),AltFKey$(X),CtrlFKey$(X)
  15. NEXT
  16. FOR X = 1 TO 10 : READ OtherKey$(X),OKey$(X) : NEXT
  17.  
  18. "KeyWatch"
  19. Byte1 = PEEK(&H417) ' case sensitivity in ZB-PC
  20. Byte2 = PEEK(&H418) ' variable names
  21.  
  22. 'These values can be easily represented as bits in ZB-PC by the
  23. 'BIN$ function. Thus if Byte1 is 1, BIN$ is "0000000000000001"
  24. 'Byte1 value 5 would return BIN$ of "0000000000000101"
  25.  
  26. Key$(1) = "N" : IF Byte2 > 127 Key$(1) = "Y" : Byte2 = Byte2-128
  27. Key$(2) = "N" : IF Byte2 > 63  Key$(2) = "Y" : Byte2 = Byte2-64
  28. Key$(3) = "N" : IF Byte2 > 31  Key$(3) = "Y" : Byte2 = Byte2-32
  29. Key$(4) = "N" : IF Byte2 > 15  Key$(4) = "Y" : Byte2 = Byte2-16
  30. Key$(5) = "N" : IF Byte2 > 1   Key$(5) = "Y" : Byte2 = Byte2-2
  31. Key$(6) = "N" : IF Byte2 > 0   Key$(6) = "Y"
  32.  
  33. ' On my extended keyboards only the Left Control and Left ALT Key returns
  34. ' the above, the Right Control Key does nothing. This appears to be a way
  35. ' to trap the left versus the right Control and Alt keys, but more testing
  36. ' may be in order
  37.  
  38. Key$(7) =  "N" : IF Byte1 > 127 Key$(7) =  "Y" : Byte1 = Byte1-128
  39. Key$(8) =  "N" : IF Byte1 > 63  Key$(8) =  "Y" : Byte1 = Byte1-64
  40. Key$(9) =  "N" : IF Byte1 > 31  Key$(9) =  "Y" : Byte1 = Byte1-32
  41. Key$(10) = "N" : IF Byte1 > 15  Key$(10) = "Y" : Byte1 = Byte1-16
  42. Key$(11) = "N" : IF Byte1 > 7   Key$(11) = "Y" : Byte1 = Byte1-8
  43. Key$(12) = "N" : IF Byte1 > 3   Key$(12) = "Y" : Byte1 = Byte1-4
  44. Key$(13) = "N" : IF Byte1 > 1   Key$(13) = "Y" : Byte1 = Byte1-2
  45. Key$(14) = "N" : IF Byte1 > 0   Key$(14) = "Y"
  46.  
  47. ' The above can be done in ZB-PC with USR3(2)
  48.  
  49. FORX=1TO14
  50.   PRINT@(10,X)Key$(X),Keyname$(X),Bit$(X)
  51. NEXT
  52. PRINT@(15,16)BIN$(PEEK(&H417)):PRINT@(55,16)BIN$(PEEK(&H418))
  53.  
  54. KeyPressed$ = INKEY$ : IF KeyPressed$ = "" GOTO "KeyWatch"
  55. IF KeyPressed$ = " " END
  56.  
  57. LONG IF LEN (KeyPressed$) = 2
  58.    Identity$ = RIGHT$(KeyPressed$,1)
  59.    FOR X = 1 TO 10
  60.      IF Identity$ = FKey$(X) PRINT@(0,21),FunctionKey$(X),,Identity$
  61.    NEXT
  62.    FOR X = 1 TO 10
  63.      IF Identity$ = ShiftFKey$(X) PRINT@(0,21),"Shifted "FunctionKey$(X),,Identity$
  64.    NEXT
  65.    FOR X = 1 TO 10
  66.      IF Identity$ = AltFKey$(X) PRINT@(0,21),"Alt "FunctionKey$(X),,Identity$
  67.    NEXT
  68.    FOR X = 1 TO 10
  69.      IF Identity$ = CtrlFKey$(X) PRINT@(0,21),"Control "FunctionKey$(X),,Identity$
  70.    NEXT
  71.    FOR X = 1 TO 10 : IF Identity$ = OKey$(X) PRINT@(0,21),OtherKey$(X),,Identity$
  72.    NEXT
  73. END IF
  74.  
  75. GOTO "KeyWatch"
  76.  
  77. DATA"InsertKeyDown          ",Bit 7 &H418
  78. DATA"CapsLockKeyDown        ",Bit 6 &H418
  79. DATA"NumLockKeyDown         ",Bit 5 &H418
  80. DATA"ScrollLockKeyDown      ",Bit 4 &H418
  81. DATA"AltKeyDown             ",Bit 1 &H418
  82. DATA"ControlKeyDown         ",Bit 0 &H418
  83. DATA"InsertKeyLockedDown    ",Bit 7 &H417
  84. DATA"CapsLockKeyLockedDown  ",Bit 6 &H417
  85. DATA"NumLockKeyLockedDown   ",Bit 5 &H417
  86. DATA"ScrollLockKeyLockedDown",Bit 4 &H417
  87. DATA"AltKeyDown             ",Bit 3 &H417
  88. DATA"ControlKeyDown         ",Bit 2 &H417
  89. DATA"LeftShiftKeyDown       ",Bit 1 &H417
  90. DATA"RightShiftKeyDown      ",Bit 0 &H417
  91. DATAF1,;,T,h,^
  92. DATAF2,<,U,i,_
  93. DATAF3,=,V,j,`
  94. DATAF4,>,W,k,a
  95. DATAF5,?,X,l,b
  96. DATAF6,@,Y,m,c
  97. DATAF7,A,Z,n,d
  98. DATAF8,B,[,o,e
  99. DATAF9,C,\,p,f
  100. DATAF10,D,],q,g
  101. DATAHome,G
  102. DATACursor Up,H
  103. DATAPage Up,I
  104. DATACursor Left,K
  105. DATACursor Right,M
  106. DATAEnd,O
  107. DATACursor Down,P
  108. DATAPage Down,Q
  109. DATAInsert,R
  110. DATADelete,S
  111.